//获取应用实例
let app = getApp();
Page({
    data: {
        //处理订单
        orderStatusOne: 'icon_doing',
        orderStatusTwo: 'icon_end',
        orderStatusThree: 'icon_end',
        orderStatusFour: 'icon_end',
        
        orderSideOneLineColour: "icon_order_succeed",
        orderSideTwoLineColour: "",
        orderSideThreeLineColour: "",
        orderSideFourLineColour: "",

        orderStatusTwoText:"收取旧批文",
        orderStatusThreeText:"业务办理",
        orderStatusFourText: '回寄新批文',
        
        orderStatusTwoTextColour: "",
        orderStatusThreeTextColour: "",
        orderStatusFourTextColour: "",

        progressTitle: "",
        progressTime: "",
        contactName: '',
        cellNum: '',
        fullAddr: '',
        isShowPage:true
    },
    onLoad(option) {
        let orderId = option.orderId,
            that = this;

        // orderId = '20180209264496642'
        let opt = {
            url: app.globalData.host+"/wx/hkmdc/detail.ajax",
            data: {
                'orderId': orderId
            },
            sucFn:(result) => {
                console.log(result.body)
                let data = result.body;
                if (data.address&&data.address.fullAddr) {
                    this.setData({
                        contactName: data.address.contactName,
                        cellNum: data.address.cellNum,
                        fullAddr: data.address.fullAddr
                    })
                }
                that.setData({
                    isShowPage:true,
                    orderId: orderId,
                    statusName: data.statusName,
                    statusDescDetail: data.statusDescDetail,

                    directType: data.directType, //1 专业 2非专业
                    //非专业
                    inlandCarNbr: data.inlandCarNbr, //车牌
                    carArchivesNbr: data.carArchivesNbr, //档案号
                    validityEnd: data.validityEnd, //有效期时间
                    inlandTelNbr: data.inlandTelNbr, //内地手机号码
                    //专业
                    witnessName: data.witnessName, //办理人姓名
                    fileNbr: data.fileNbr,
                    
                    workBookFee: data.workBookFee/100, //工本费
                    serviceFee: data.serviceFee/100, //服务费
                    totalFee: data.totalFee/100, //总计

                    progressTitle: data.progressTitle,
                    progressTime: app.toYMDHMSDate(data.progressTime),
                    
                    payText: data.licensingWay == 1?'线下到付':'微信支付',
                    licensingWay: data.licensingWay,
                    payNo: data.payNo,
                    createTime: app.toYMDHMSDate(data.createTime),
                    chargeTime: data.chargeTime?app.toYMDHMSDate(data.chargeTime):null,
                    completeTimeText: data.status==8?"完成时间":"关闭时间",
                    completeTime: data.completeTime?app.toYMDHMSDate(data.completeTime):null,
                });

                /** status 对应的状态
                 * 申请延期：<10
                    收取旧批文：10<=& <=29 &/=28
                    业务办理：28
                    回寄新批文：>=40
                 */
                 /*
                       icon_complete  绿色中圆
                       icon_end  灰色中圆
                       icon_failed 红色中圆
                       
	                 * icon_doing      成功绿色大圆
	                 * icon_fail        失败红色大圆
	                 *
	                 * bg-color-blue 蓝色背景
	                 * bg-color-red  红色背景
	                 * */
                let status = data.status;
                if (status < 10) {
                    that.setData({
                        orderStatusOne: "icon_doing",

                        orderSideOneLineColour: "",
                        orderSideTwoLineColour: "",
                        orderSideThreeLineColour: "",

                        orderStatusTwoTextColour: "",
                        orderStatusThreeTextColour: ""
                    });
                } else if (status == 28) {
                    that.setData({
                        orderStatusOne: 'bg-color-blue',
                        orderStatusTwo: 'bg-color-blue',
                        orderStatusThree: 'icon_doing',
                        
                        orderSideOneLineColour: 'bg-color-blue',
                        orderSideTwoLineColour: 'bg-color-blue',
                        orderSideThreeLineColour: 'bg-color-blue',

                        orderStatusTwoTextColour: "font-color-blue",
                        orderStatusThreeTextColour: "font-color-blue"
                    });
                }else if (status <= 10 || status <=29 ) {
                    that.setData({
                        orderStatusOne: "bg-color-blue",
                        orderStatusTwo: "icon_doing",
                        
                        orderSideOneLineColour: "bg-color-blue",

                        orderStatusTwoTextColour: "font-color-blue",
                        orderStatusThreeTextColour: ""
                    });
                } else if (status>=40) {
                    that.setData({
                        orderStatusOne: 'icon_complete',
                        orderStatusTwo: 'icon_complete',
                        orderStatusThree: 'icon_complete',
                        orderStatusFour: 'icon_doing',
                        
                        orderSideOneLineColour: "bg-color-blue",
                        orderSideTwoLineColour: 'bg-color-blue',
                        orderSideThreeLineColour: 'bg-color-blue',
                        orderSideFourLineColour: 'bg-color-blue',
                        
                        orderStatusTwoTextColour: "font-color-blue",
                        orderStatusThreeTextColour: 'font-color-blue',
                        orderStatusFourTextColour: 'font-color-blue',
                    });
                }
            }
        };
        app.ajax(opt);

    },
    onHide:function () {
        app.removeStorageSync(app.globalData.cacheOrderResKey);
    },
    progressTap:function(e){
        var orderId = e.target.dataset.id;
        app.navigateTo({
            url: '../progress/progress?orderId='+orderId
        });
    },
});
